package com.tlsy.commerce.model.converter;

import com.tlsy.commerce.model_enum.StatusEnum;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author Tlsy
 * @version commerce 0.0.1
 * @date 2017/4/19  17:07
 */
@Converter
public class StatusConverter implements AttributeConverter<StatusEnum,Integer>{

    public Integer convertToDatabaseColumn(StatusEnum statusEnum) {
        if(statusEnum==null){
            return null;
        }
        return statusEnum.value();
    }

    public StatusEnum convertToEntityAttribute(Integer integer) {
        if(integer==null){
            return null;
        }
        return StatusEnum.fromValue(integer);
    }
}
